﻿package com.library.utils.vily
{
	//org.vily.utils.CircleDrawer
	/**a3263826 
		本类用于实现绘制与圆相关的图形
	*/
	import flash.display.Sprite;
	public class CircleDrawer{
		
		public var lineThickness:Number = 1.0;
		public var lineAlpha:Number = 1.0;
		public var lineColor:Number = 0x000000;
		//
		public var fillAlpha:Number = 1.0;
		public var fillColor:Number = 0x55aa55;
		
		private var drawer:DrawArc = null;
		public function CircleDrawer(){
			init();
		}
		private function init():void{
			drawer = new DrawArc();
		}
		
		/**
			绘制有填充和边框的圆环
			@param		spr:Sprite,绘制内容的容器spr
			@param		c_pos:Vector_2D,圆的中心坐标
			@param		r_a_num:Number = 100,圆环一个环的半径
			@param		r_b_num:Number = 150,圆环一个环的半径
			@param		startAng:Number = 0,起始的角度
			@param		dArcAng:Number = 10,圆环所跨过的总的角度
			@param		speed_dis:Number = 5,绘制圆环时候的两个圆环上的相邻点间的距离
			@param		isClear:Boolean = true,是否使用spr.graphics.clear();			
		*/
		public function drawCirque(
								   spr:Sprite,
								   c_pos:Vector_2D,
								   r_a_num:Number = 100,
								   r_b_num:Number = 150,
								   startAng:Number = 0,
								   dArcAng:Number = 10,
								   speed_dis:Number = 5,
								   isClear:Boolean = true
								   ):void{
			var t_0_pos:Vector_2D = null;
			var t_1_pos:Vector_2D = null;
			var pos_arr:Array = drawer.getAngleArcPosArr(c_pos,startAng,r_a_num,dArcAng,speed_dis);
			if(pos_arr == null){
				return;
			}
			if(isClear){
				spr.graphics.clear();
			}
			var num:int = pos_arr.length;
			if(num>0){				
				spr.graphics.lineStyle(lineThickness,lineColor,lineAlpha,false);
				spr.graphics.beginFill(fillColor,fillAlpha);
				spr.graphics.moveTo(pos_arr[0].x,pos_arr[0].y);
				for(var i:int = 1;i<num; i++){
					spr.graphics.lineTo(pos_arr[i].x,pos_arr[i].y);
				}
			}
			t_0_pos = pos_arr[0];
			t_1_pos = pos_arr[num - 1];
			
			pos_arr = drawer.getAngleArcPosArr(c_pos,startAng,r_b_num,dArcAng,speed_dis);
			if(pos_arr == null){
				return;
			}
			
			num = pos_arr.length;
			if(num>0){
				spr.graphics.lineTo(t_1_pos.x,t_1_pos.y);
				spr.graphics.lineTo(pos_arr[num-1].x,pos_arr[num-1].y);
				for(i = num - 1;i>=0; i--){
					spr.graphics.lineTo(pos_arr[i].x,pos_arr[i].y);
				}
				spr.graphics.lineTo(t_0_pos.x,t_0_pos.y);				
				spr.graphics.endFill();
				
			}
			t_0_pos = null;
			t_1_pos = null;
		}
		/**
			绘制无填充有边框的圆环
			@param		spr:Sprite,绘制内容的容器spr
			@param		c_pos:Vector_2D,圆的中心坐标
			@param		r_a_num:Number = 100,圆环一个环的半径
			@param		r_b_num:Number = 150,圆环一个环的半径
			@param		startAng:Number = 0,起始的角度
			@param		dArcAng:Number = 10,圆环所跨过的总的角度
			@param		speed_dis:Number = 5,绘制圆环时候的两个圆环上的相邻点间的距离
			@param		isClear:Boolean = true,是否使用spr.graphics.clear();
			@param		isCross:Boolean = true,是否连通圆环
		*/
		public function drawCirqueFrame(
										spr:Sprite,
										c_pos:Vector_2D,
										r_a_num:Number = 100,
										r_b_num:Number = 150,
										startAng:Number = 0,
										dArcAng:Number = 10,
										speed_dis:Number = 5,
										isClear:Boolean = true,
										isCross:Boolean = true
										):void{
			var t_0_pos:Vector_2D = null;
			var t_1_pos:Vector_2D = null;
			var pos_arr:Array = drawer.getAngleArcPosArr(c_pos,startAng,r_a_num,dArcAng,speed_dis);
			if(pos_arr == null){
				return;
			}
			if(isClear){
				spr.graphics.clear();
			}
			var num:int = pos_arr.length;
			if(num>0){				
				spr.graphics.lineStyle(lineThickness,lineColor,lineAlpha,false);
				spr.graphics.moveTo(pos_arr[0].x,pos_arr[0].y);
				for(var i:int = 1;i<num; i++){
					spr.graphics.lineTo(pos_arr[i].x,pos_arr[i].y);
				}
			}
			t_0_pos = pos_arr[0];
			t_1_pos = pos_arr[num - 1];
			
			pos_arr = drawer.getAngleArcPosArr(c_pos,startAng,r_b_num,dArcAng,speed_dis);
			if(pos_arr == null){
				return;
			}
			
			num = pos_arr.length;
			if(num>0){
				if(isCross && dArcAng == 360){					
					spr.graphics.moveTo(pos_arr[num - 1].x,pos_arr[num - 1].y);
				}else{
					spr.graphics.lineTo(t_1_pos.x,t_1_pos.y);
					spr.graphics.lineTo(pos_arr[num-1].x,pos_arr[num-1].y);
				}
				for(i = num - 1;i>=0; i--){
					spr.graphics.lineTo(pos_arr[i].x,pos_arr[i].y);
				}
				if(isCross && dArcAng == 360){					
				}else{
					spr.graphics.lineTo(t_0_pos.x,t_0_pos.y);
				}
			}
			t_0_pos = null;
			t_1_pos = null;
		}
		
		/**
			绘制有填充无边框的圆环
			@param		spr:Sprite,绘制内容的容器spr
			@param		c_pos:Vector_2D,圆的中心坐标
			@param		r_a_num:Number = 100,圆环一个环的半径
			@param		r_b_num:Number = 150,圆环一个环的半径
			@param		startAng:Number = 0,起始的角度
			@param		dArcAng:Number = 10,圆环所跨过的总的角度
			@param		speed_dis:Number = 5,绘制圆环时候的两个圆环上的相邻点间的距离
			@param		isClear:Boolean = true,是否使用spr.graphics.clear();			
		*/
		public function drawCirqueShape(spr:Sprite,c_pos:Vector_2D,r_a_num:Number = 100,r_b_num:Number = 150,startAng:Number = 0,dArcAng:Number = 10,speed_dis:Number = 5,isClear:Boolean = true):void{
			var t_0_pos:Vector_2D = null;
			var t_1_pos:Vector_2D = null;
			var pos_arr:Array = drawer.getAngleArcPosArr(c_pos,startAng,r_a_num,dArcAng,speed_dis);
			if(pos_arr == null){
				return;
			}
			if(isClear){				
				spr.graphics.clear();
			}
			var num:int = pos_arr.length;
			if(num>0){				
				spr.graphics.beginFill(fillColor,fillAlpha);
				spr.graphics.moveTo(pos_arr[0].x,pos_arr[0].y);
				for(var i:int = 1;i<num; i++){
					spr.graphics.lineTo(pos_arr[i].x,pos_arr[i].y);
				}
			}
			t_0_pos = pos_arr[0];
			t_1_pos = pos_arr[num - 1];
			pos_arr.splice(0);
			pos_arr = drawer.getAngleArcPosArr(c_pos,startAng,r_b_num,dArcAng,speed_dis);
			if(pos_arr == null){
				return;
			}
			num = pos_arr.length;
			if(num>0){				
				spr.graphics.lineTo(t_1_pos.x,t_1_pos.y);
				spr.graphics.lineTo(pos_arr[num-1].x,pos_arr[num-1].y);
				
				for(i = num - 1;i>=0; i--){
					spr.graphics.lineTo(pos_arr[i].x,pos_arr[i].y);
				}
				spr.graphics.lineTo(t_0_pos.x,t_0_pos.y);
				spr.graphics.endFill();
				
			}
			pos_arr.splice(0);
			pos_arr = null;
			t_0_pos = null;
			t_1_pos = null;
		}
		
		/**
			绘制有边框和填充的扇形
			@param		spr:Sprite,绘制内容的容器spr
			@param		c_pos:Vector_2D,圆的中心坐标
			@param		r_a_num:Number = 100,扇形的半径			
			@param		startAng:Number = 0,起始的角度
			@param		dArcAng:Number = 10,扇形所跨过的总的角度
			@param		speed_dis:Number = 5,绘制圆环时候的圆弧上的相邻点间的距离
			@param		isClear:Boolean = true,是否使用spr.graphics.clear();			
		*/
		public function drawSector(spr:Sprite,c_pos:Vector_2D,r_a_num:Number = 100,startAng:Number = 0,dArcAng:Number = 10,speed_dis:Number = 5,isClear:Boolean = true):void{
			
			var pos_arr:Array = drawer.getAngleArcPosArr(c_pos,startAng,r_a_num,dArcAng,speed_dis);
			if(pos_arr == null){
				return;
			}
			if(isClear){				
				spr.graphics.clear();
			}
			var num:int = pos_arr.length;
			if(num>0){
				spr.graphics.lineStyle(lineThickness,lineColor,lineAlpha,false);
				spr.graphics.beginFill(fillColor,fillAlpha);
				spr.graphics.moveTo(c_pos.x,c_pos.y);
				for(var i:int = 0;i<num; i++){
					spr.graphics.lineTo(pos_arr[i].x,pos_arr[i].y);
				}
				spr.graphics.lineTo(c_pos.x,c_pos.y);
				spr.graphics.endFill();
			}			
			pos_arr.splice(0);
			pos_arr = null;
		}
		/**
			绘制有边框无填充的扇形
			@param		spr:Sprite,绘制内容的容器spr
			@param		c_pos:Vector_2D,圆的中心坐标
			@param		r_a_num:Number = 100,扇形的半径			
			@param		startAng:Number = 0,起始的角度
			@param		dArcAng:Number = 10,扇形所跨过的总的角度
			@param		speed_dis:Number = 5,绘制圆环时候的圆弧上的相邻点间的距离
			@param		isClear:Boolean = true,是否使用spr.graphics.clear();			
		*/
		public function drawSectorFrame(spr:Sprite,c_pos:Vector_2D,r_a_num:Number = 100,startAng:Number = 0,dArcAng:Number = 10,speed_dis:Number = 5,isClear:Boolean = true):void{
			
			var pos_arr:Array = drawer.getAngleArcPosArr(c_pos,startAng,r_a_num,dArcAng,speed_dis);
			if(pos_arr == null){
				return;
			}
			if(isClear){				
				spr.graphics.clear();
			}
			var num:int = pos_arr.length;
			if(num>0){
				spr.graphics.lineStyle(lineThickness,lineColor,lineAlpha,false);				
				spr.graphics.moveTo(c_pos.x,c_pos.y);
				for(var i:int = 0;i<num; i++){
					spr.graphics.lineTo(pos_arr[i].x,pos_arr[i].y);
				}
				spr.graphics.lineTo(c_pos.x,c_pos.y);
			}			
			pos_arr.splice(0);
			pos_arr = null;
		}
		/**
			绘制无边框有填充的扇形
			@param		spr:Sprite,绘制内容的容器spr
			@param		c_pos:Vector_2D,圆的中心坐标
			@param		r_a_num:Number = 100,扇形的半径			
			@param		startAng:Number = 0,起始的角度
			@param		dArcAng:Number = 10,扇形所跨过的总的角度
			@param		speed_dis:Number = 5,绘制圆环时候的圆弧上的相邻点间的距离
			@param		isClear:Boolean = true,是否使用spr.graphics.clear();			
		*/
		public function drawSectorShape(spr:Sprite,c_pos:Vector_2D,r_a_num:Number = 100,startAng:Number = 0,dArcAng:Number = 10,speed_dis:Number = 5,isClear:Boolean = true):void{
			
			var pos_arr:Array = drawer.getAngleArcPosArr(c_pos,startAng,r_a_num,dArcAng,speed_dis);
			if(pos_arr == null){
				return;
			}
			if(isClear){				
				spr.graphics.clear();
			}
			var num:int = pos_arr.length;
			if(num>0){				
				spr.graphics.beginFill(fillColor,fillAlpha);
				spr.graphics.moveTo(c_pos.x,c_pos.y);
				for(var i:int = 0;i<num; i++){
					spr.graphics.lineTo(pos_arr[i].x,pos_arr[i].y);
				}
				spr.graphics.lineTo(c_pos.x,c_pos.y);
				spr.graphics.endFill();
			}			
			pos_arr.splice(0);
			pos_arr = null;
		}
	}
}